import axios from 'axios';

import { ElMessage } from 'element-plus'

const service = axios.create({
    baseURL: 'http://api.example.com', // 设置基础 URL
    // 其他配置...
  });


service.interceptors.request.use(
	(config) => {
		
		return config
	},
	error => {
		return Promise.reject(error)
	}
)


service.interceptors.response.use(
	response => {
		if (response.status !== 200) {
			return Promise.reject(new Error(response.statusText || 'Error'))
		}
 
		const res = response.data
		// 响应成功 TODO 这里要填上业务成功的状态码
		if (res.code === 200) {
			return res
		}
 
		// 错误提示
		ElMessage.error(res.msg)
 
		return Promise.reject(new Error(res.msg || 'Error'))
	},
	error => {
		ElMessage.error(error.message)
		return Promise.reject(error)
	}
)



export default service